package com.example.examapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;



import android.R.color;
import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 功能首页
 * @author FenGKun
 *
 */
public class ContainFragment extends FragmentActivity {


    /** 找工作 */
    public Button tv_findWork;
    /** 招人才 */
    private TextView tv_findTalents;
    /** 找学校 */
    private TextView tv_findSchool;
    /** 招学生 */
    private TextView tv_findStudent;
    /** 具体内容 */
    private androidx.fragment.app.Fragment contentFragment;
    /** 管理fragment */
    private FragmentManager fragmentManager;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contain_fragment);

        // 初始化数据
        // 找工作
        tv_findWork = (Button)findViewById(R.id.tvWork);
        tv_findWork.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                tv_findWork.setBackgroundColor(0xffffffff);
                tv_findWork.setTextColor(0XFFE4BA3F);
                tv_findTalents.setBackgroundColor(0Xffffffff);
                tv_findTalents.setTextColor(0XFFE4BA3F);
                tv_findSchool.setBackgroundColor(0xffffffff);
                tv_findSchool.setTextColor(0XFFE4BA3F);
                tv_findStudent.setBackgroundColor(0xffffffff);
                tv_findStudent.setTextColor(0XFFE4BA3F);
                TextView textview = (TextView) v;
                textview.setBackgroundColor(0XFFE4BA3F);
                textview.setTextColor(0xff000000);
                // 开启一个Fragment事务
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                switch (v.getId()) {
                    // 找工作
                    case R.id.tvWork:
                        contentFragment = new FindWorkFragement();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 招人才
                    case R.id.tvTalents:
                        contentFragment = new FragmentTwo();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 找学校
                    case R.id.tvSchool:
                        contentFragment = new FragementOne();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 招学生
                    case R.id.tvStudent:
                        contentFragment = new FragmentThree();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;

                    default:
                        break;
                }
                transaction.commit();
            }
        });
        // 招人才
        tv_findTalents = (TextView) findViewById(R.id.tvTalents);
        tv_findTalents.setOnClickListener(itemClick);
        // 找学校
        tv_findSchool = (TextView) findViewById(R.id.tvSchool);
        tv_findSchool.setOnClickListener(itemClick);
        // 招学生
        tv_findStudent = (TextView) findViewById(R.id.tvStudent);
        tv_findStudent.setOnClickListener(itemClick);
        // fragment管理者
        fragmentManager = getSupportFragmentManager();
    }
    /**
     * 初始化变量
     */
    private void initUi() {
        // 找工作
        tv_findWork = (Button) findViewById(R.id.tvWork);
        tv_findWork.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                tv_findWork.setBackgroundColor(0xffffffff);
                tv_findWork.setTextColor(0XFFE4BA3F);
                tv_findTalents.setBackgroundColor(0Xffffffff);
                tv_findTalents.setTextColor(0XFFE4BA3F);
                tv_findSchool.setBackgroundColor(0xffffffff);
                tv_findSchool.setTextColor(0XFFE4BA3F);
                tv_findStudent.setBackgroundColor(0xffffffff);
                tv_findStudent.setTextColor(0XFFE4BA3F);
                TextView textview = (TextView) v;
                textview.setBackgroundColor(0XFFE4BA3F);
                textview.setTextColor(0xff000000);
                // 开启一个Fragment事务
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                switch (v.getId()) {
                    // 找工作
                    case R.id.tvWork:
                        contentFragment = new FindWorkFragement();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 招人才
                    case R.id.tvTalents:
                        contentFragment = new FragmentTwo();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 找学校
                    case R.id.tvSchool:
                        contentFragment = new FragementOne();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;
                    // 招学生
                    case R.id.tvStudent:
                        contentFragment = new FragmentThree();
                        transaction.replace(R.id.fragmentPager, contentFragment);
                        break;

                    default:
                        break;
                }
                transaction.commit();
            }
        });
        // 招人才
        tv_findTalents = (TextView) findViewById(R.id.tvTalents);
        tv_findTalents.setOnClickListener(itemClick);
        // 找学校
        tv_findSchool = (TextView) findViewById(R.id.tvSchool);
        tv_findSchool.setOnClickListener(itemClick);
        // 招学生
        tv_findStudent = (TextView) findViewById(R.id.tvStudent);
        tv_findStudent.setOnClickListener(itemClick);
        // fragment管理者
        fragmentManager = getSupportFragmentManager();
    }

    /**
     * 点击选项
     */
    public View.OnClickListener itemClick = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            tv_findWork.setBackgroundColor(0xffffffff);
            tv_findWork.setTextColor(0XFFE4BA3F);
            tv_findTalents.setBackgroundColor(0Xffffffff);
            tv_findTalents.setTextColor(0XFFE4BA3F);
            tv_findSchool.setBackgroundColor(0xffffffff);
            tv_findSchool.setTextColor(0XFFE4BA3F);
            tv_findStudent.setBackgroundColor(0xffffffff);
            tv_findStudent.setTextColor(0XFFE4BA3F);
            TextView textview = (TextView) v;
            textview.setBackgroundColor(0XFFE4BA3F);
            textview.setTextColor(0xff000000);
            // 开启一个Fragment事务
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            switch (v.getId()) {
                // 找工作
                case R.id.tvWork:
                    contentFragment = new FindWorkFragement();
                    transaction.replace(R.id.fragmentPager, contentFragment);
                    break;
                // 招人才
                case R.id.tvTalents:
                    contentFragment = new FragmentTwo();
                    transaction.replace(R.id.fragmentPager, contentFragment);
                    break;
                // 找学校
                case R.id.tvSchool:
                    contentFragment = new FragementOne();
                    transaction.replace(R.id.fragmentPager, contentFragment);
                    break;
                // 招学生
                case R.id.tvStudent:
                    contentFragment = new FragmentThree();
                    transaction.replace(R.id.fragmentPager, contentFragment);
                    break;

                default:
                    break;
            }
            transaction.commit();
        }
    };



}
